package com.igroupes.ovineherd.model.Style;

import cn.hutool.json.JSONObject;
import com.igroupes.ovineherd.exception.ModelException;
import lombok.Data;
import lombok.ToString;

import java.util.List;

/**
 * 多选
 */
@Data
@ToString(callSuper = true)
public class ChoiceListStyle  implements IStyle{
    protected String label;
    protected String type;
    protected Boolean required;
    protected String desc;
    protected JSONObject items; //选集合
    protected List value;

    protected ChoiceListStyle() {
    }

    protected ChoiceListStyle(String label, Boolean required, JSONObject items) {
        this.label = label;
        this.required = required;
        this.items = items;
    }

    protected ChoiceListStyle(String label, JSONObject items, String desc) {
        this.label = label;
        this.required = true;
        this.items = items;
        this.desc = desc;
    }
    @Override
    public Boolean verify(Object o) {
        if(!(o instanceof ChoiceListStyle)){
            throw new ModelException("校验style类类型错误，choice");
        }
        ChoiceListStyle choiceListStyle = (ChoiceListStyle) o;
        if(choiceListStyle.getRequired()){
            if( null == choiceListStyle.getItems() || 0>= choiceListStyle.getItems().size()){
                throw new ModelException(choiceListStyle.getLabel()+"值不能为空！");
            }
        }
        return true;
    }
}
